package com.fcg.redis.orgtree.bean;

import com.alibaba.fastjson.annotation.JSONField;
import lombok.Builder;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.Objects;

/**
 * 组织机构实体类
 * @author FCG
 */
@Data
@Builder
public class OrgBean {
    /** 节点id*/
    private String nodeId;
    /** 节点名称*/
    private String nodeName;
    /** 子节点列表*/
    @JSONField(serialize = false)
    private transient List<OrgBean> children;
    /** 当前节点附属信息*/
    private Object info;

    public OrgBean() {
    }

    public OrgBean(String nodeId, String nodeName, List<OrgBean> children, Object info) {
        this.nodeId = nodeId;
        this.nodeName = nodeName;
        this.children = children;
        this.info = info;
    }

    public OrgBean copyIngnoreChildren() {
        OrgBean desBean = new OrgBean();
        BeanUtils.copyProperties(this, desBean, "children", "info");
        return desBean;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        OrgBean orgBean = (OrgBean) o;
        return Objects.equals(nodeId, orgBean.nodeId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(nodeId);
    }
}
